package com.ruoyi.web.controller.danger;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.entity.LightningData;
import com.ruoyi.system.service.LightningDataService;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * (LightningData)表控制层
 * @since 2023-03-08 13:45:55
 */
@RestController
@RequestMapping("/lightningData")
public class LightningDataController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private LightningDataService lightningDataService;

    /**
     * 分页查询
     * @param lightningData 筛选条件
     * @return 查询结果
     */
    @GetMapping("/list")
    public TableDataInfo queryByPage(LightningData lightningData) {
        startPage();
        List<LightningData> lightningDataList = this.lightningDataService.queryByPage(lightningData);
        return getDataTable(lightningDataList);
    }

    /**
     * 通过主键查询单条数据
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<LightningData> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.lightningDataService.queryById(id));
    }

    /**
     * 新增数据
     * @param lightningData 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<LightningData> add(LightningData lightningData) {
        return ResponseEntity.ok(this.lightningDataService.insert(lightningData));
    }

    /**
     * 编辑数据
     * @param lightningData 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<LightningData> edit(LightningData lightningData) {
        return ResponseEntity.ok(this.lightningDataService.update(lightningData));
    }

    /**
     * 删除数据
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.lightningDataService.deleteById(id));
    }

    /**
     * @return 查询结果
     */
    @GetMapping("/queryYearOrMonthList")
    public AjaxResult queryYearOrMonthList(String startTime, String endTime) {
        List<LightningData> list = this.lightningDataService.queryYearOrMonthList(startTime,endTime);
        return AjaxResult.success(list);
    }

}

